package com.rmt.www.serviceImpl;

import com.opensymphony.xwork2.ActionContext;
import com.rmt.www.service.TestManageTestCaseService;
import com.rmt.www.utility.SystemTime;
import com.rmt.www.vo.TestArtifact;
import com.rmt.www.vo.TestArtifactRequest;
import com.rmt.www.vo.User;
import com.rmt.www.constant.RequestType;
import com.rmt.www.dao.*;

public class TestManageTestCaseServiceImpl implements TestManageTestCaseService {

	private TestArtifactRequestDao testArtifactRequestDao;
	private TestArtifactDao testArtifactDao;
	private UserDao userDao;
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public TestArtifactDao getTestArtifactDao() {
		return testArtifactDao;
	}

	public void setTestArtifactDao(TestArtifactDao testArtifactDao) {
		this.testArtifactDao = testArtifactDao;
	}

	public void addNewTestCaseRequest(TestArtifactRequest request) {
		testArtifactRequestDao.insertTestArtifactRequest(request);
	}

	public void deleteTestCase(int id) {
		TestArtifact ta = testArtifactDao.getTestArtifactById(id);
		TestArtifactRequest r = new TestArtifactRequest();
		
		r.setTestartifactid(ta.getId());
		r.setPid(ta.getPid());
		r.setTestcasetype(ta.getTestcasetype());
		r.setTitle(ta.getTitle());
		r.setPriority(ta.getPriority());
		r.setPrecondition(ta.getPrecondition());
		r.setInput(ta.getInput());
		r.setTestdata(ta.getTestdata());
		r.setSteps(ta.getSteps());
		r.setExpectedresult(ta.getExpectedresult());
		r.setPostcondition(ta.getPostcondition());
		r.setEffort(ta.getEffort());
		r.setCost(ta.getCost());
		r.setRisk(ta.getRisk());
		r.setComment(ta.getComment());
		r.setUpdatedtimes(ta.getUpdatedtimes());
		r.setVersion(ta.getVersion());
		r.setStatus(ta.getStatus());
		r.setCreaterid(ta.getCreaterid());
		r.setCreatedtime(ta.getCreatedtime());
		//r.setTestartifactid(testartifactid);
		
		r.setRequestType(RequestType.DELETE);
	 	r.setUpdatedtime(new java.sql.Timestamp(SystemTime.getSystemTime().getTime()));
		User u=(User)ActionContext.getContext().getSession().get("currentUser");
		r.setUpdaterid(u.getUid());
		testArtifactRequestDao.insertTestArtifactRequest(r);
	}

	public void updateTestCase(TestArtifactRequest request) {
		
	}

	public TestArtifactRequestDao getTestArtifactRequestDao() {
		return testArtifactRequestDao;
	}

	public void setTestArtifactRequestDao(
			TestArtifactRequestDao testArtifactRequestDao) {
		this.testArtifactRequestDao = testArtifactRequestDao;
	}

	public TestArtifact getTestArtifact(int id) {
		TestArtifact a = testArtifactDao.getTestArtifactById(id);
		a.set_authorname(userDao.getUser(a.getCreaterid()).getName());
 		a.set_updatername(userDao.getUser(a.getUpdaterid()).getName());
 		return a;
	}

}
